/*
* pps_bom
*/
package com.pitop.assembly.ctrl;

import com.alibaba.fastjson.JSON;
import com.pitop.assembly.entity.AssemblyImage;
import com.pitop.assembly.service.AssemblyImageSV;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
* 设计图库 控制器
*
* @author berton
*/
@RestController
@RequestMapping("/assemblyImage")
@Slf4j
@Api(value = "设计图库控制器", description = "设计图库控制器")
public class AssemblyImageCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private AssemblyImageSV assemblyImageSV;

    /**
    * 查询AssemblyImage一个详情信息
    * @param id 
    * @param assemblyCode 组件编码
    * @param code 图纸编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询AssemblyImage一个详情信息", notes = "查询AssemblyImage一个详情信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "query"),
        @ApiImplicitParam(name = "assemblyCode", value = "组件编码",dataType = "java.lang.String", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "图纸编码",dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public AssemblyImage load(Long id,String assemblyCode,String code) {
        if(id==null){
        return null;
        }
        if(assemblyCode==null){
        return null;
        }
        if(code==null){
        return null;
        }
        AssemblyImage assemblyImage = assemblyImageSV.load(id,assemblyCode,code);
        log.info(JSON.toJSONString(assemblyImage));
        return assemblyImage;
    }


    /**
    * 根据条件id查询AssemblyImage一个详情信息
    *
    * @param id 
    * @return BeanRet
    */
    @ApiOperation(value = "查询AssemblyImage一个详情信息", notes = "查询AssemblyImage一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "id", value = "",dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public AssemblyImage loadById(@PathVariable Long id) {
        if(id==null){
           return null;
        }
        AssemblyImage assemblyImage = assemblyImageSV.loadById(id);
        log.info(JSON.toJSONString(assemblyImage));
        return assemblyImage;
    }
    /**
    * 根据条件assemblyCode查询AssemblyImage一个详情信息
    *
    * @param assemblyCode 组件编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询AssemblyImage一个详情信息", notes = "查询AssemblyImage一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "assemblyCode", value = "组件编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/assemblyCode/{assemblyCode}")
    @ResponseBody
    public AssemblyImage loadByAssemblyCode(@PathVariable String assemblyCode) {
        if(assemblyCode==null){
           return null;
        }
        AssemblyImage assemblyImage = assemblyImageSV.loadByAssemblyCode(assemblyCode);
        log.info(JSON.toJSONString(assemblyImage));
        return assemblyImage;
    }
    /**
    * 根据条件code查询AssemblyImage一个详情信息
    *
    * @param code 图纸编码
    * @return BeanRet
    */
    @ApiOperation(value = "查询AssemblyImage一个详情信息", notes = "查询AssemblyImage一个详情信息")
    @ApiImplicitParams({
       @ApiImplicitParam(name = "code", value = "图纸编码",dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public AssemblyImage loadByCode(@PathVariable String code) {
        if(code==null){
           return null;
        }
        AssemblyImage assemblyImage = assemblyImageSV.loadByCode(code);
        log.info(JSON.toJSONString(assemblyImage));
        return assemblyImage;
    }


    /**
    * 查询AssemblyImage信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询AssemblyImage信息集合", notes = "查询AssemblyImage信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    })
    @PostMapping(value = "/list")
    @ResponseBody
    public List<AssemblyImage> list(@RequestBody @ApiIgnore AssemblyImage assemblyImage,Integer curPage,Integer pageSize) {
        Page<AssemblyImage> page=new Page<AssemblyImage>(pageSize,curPage);
        List<AssemblyImage> assemblyImages = assemblyImageSV.list(assemblyImage,page.genRowStart(),page.getPageSize());
        int total = assemblyImageSV.count(assemblyImage);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return assemblyImages;
    }

    /**
    * 查询AssemblyImage信息集合
    *
    * @return 分页对象
    */
    @ApiOperation(value = "查询AssemblyImage信息集合", notes = "查询AssemblyImage信息集合")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
    @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "图纸编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public List<AssemblyImage> listByPk(Long id,String assemblyCode,String code,Integer curPage,Integer pageSize) {
        Page<AssemblyImage> page=new Page<AssemblyImage>(pageSize,curPage);
        List<AssemblyImage> assemblyImages = assemblyImageSV.list(id,assemblyCode,code, page.genRowStart(),page.getPageSize());
        int total = assemblyImageSV.count(id,assemblyCode,code);
        page.setTotalRow(total);
        log.info(JSON.toJSONString(page));
        return assemblyImages;
    }

    /**
    * 统计AssemblyImage信息数量根据主键
    *
    * @return 总条数
    */
    @ApiOperation(value = " 统计AssemblyImage信息数量根据主键", notes = " 统计AssemblyImage信息数量根据主键")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "图纸编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(Long id,String assemblyCode,String code) {
        return assemblyImageSV.count(id,assemblyCode,code);
    }

    /**
    * 统计AssemblyImage信息数量
    *
    * @return 总条数
    */
    @ApiOperation(value = "统计AssemblyImage信息数量", notes = "统计AssemblyImage信息数量")
    @ApiImplicitParams({
    @ApiImplicitParam(name = "id", value = "", paramType = "query"),
    @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
    @ApiImplicitParam(name = "code", value = "图纸编码", paramType = "query"),
    @ApiImplicitParam(name = "path", value = "图纸地址", paramType = "query"),
    @ApiImplicitParam(name = "summary", value = "备注 最多64汉字，128英文字符", paramType = "query")
    })
    @PostMapping(value = "/count")
    @ResponseBody
    public Integer count(@RequestBody AssemblyImage assemblyImage) {
        return assemblyImageSV.count(assemblyImage);
    }

    /**
    * 创建AssemblyImage
    *
    * @return BeanRet
    */
    @ApiOperation(value = "创建AssemblyImage", notes = "创建AssemblyImage")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "path", value = "图纸地址", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "备注 最多64汉字，128英文字符", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public AssemblyImage build(@RequestBody @ApiIgnore AssemblyImage assemblyImage) {
        assemblyImageSV.save(assemblyImage);
        return assemblyImage;
    }

    /**
    * 修改AssemblyImage
    *
    * @return BeanRet
    */
    @ApiOperation(value = "修改AssemblyImage", notes = "修改AssemblyImage")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "图纸编码", paramType = "query"),
        @ApiImplicitParam(name = "path", value = "图纸地址", paramType = "query"),
        @ApiImplicitParam(name = "summary", value = "备注 最多64汉字，128英文字符", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public AssemblyImage modify(@RequestBody @ApiIgnore AssemblyImage assemblyImage) {
        assemblyImageSV.modify(assemblyImage);
        return assemblyImage;
    }

    /**
    * 删除AssemblyImage
    *
    * @return BeanRet
    */
    @ApiOperation(value = "删除AssemblyImage", notes = "删除AssemblyImage")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "", paramType = "query"),
        @ApiImplicitParam(name = "assemblyCode", value = "组件编码", paramType = "query"),
        @ApiImplicitParam(name = "code", value = "图纸编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id,String assemblyCode,String code) {
        assemblyImageSV.delete(id,assemblyCode,code);
        return BeanRet.create(true, "删除AssemblyImage成功");
    }

}
